#include "stdafx.h"
#include "Sort.h"
#pragma once; 


const int DefaultSize = 10;
//.h
template <class T> 
struct Node {
	T* data;
	Node* next;
};


template <class T> 
class Array            
{
private:
	Node<T>*  pT;
	int  iSize;

public:
   Array();
   Array(int number);
   Array(const Array &rhs);
   ~Array() { }

   // operator =
   Array& operator=(const Array&);

   // get element at position
   T& operator[](int offSet);
   const T& operator[](int offSet) const;

   int getSize() const { return iSize; }

   void sort(Sort<T>* sortStrategy)
   {
	   sortStrategy->sort(*this);
   }
};

// .cpp
template <class T>
Array<T>::Array()
{
	iSize = DefaultSize;
	pT = new Node<T>;
	pT->data = new T();
	pT->next = NULL;

	 for (int i = 1; i<iSize; i++)
	 {
		Node<T> *newNode = new Node<T>;
		newNode->data = new T();
		newNode->next = NULL;

		Node<T> *cur = pT;
		while(cur) {
			if(cur->next == NULL) {
				cur->next = newNode;
				break;
			}
			cur = cur->next;
		}

	 }
}

template <class T>
Array<T>::Array(int number)
{
	iSize = number;
	pT = new Node<T>;
	pT.data = new T();
	pT.next = NULL;

	 for (int i = 1; i<iSize; i++)
	 {
		Node<T> *newNode = new Node<T>;
		newNode->data = n;
		newNode->next = NULL;

		Node<T> *cur = pT;
		while(cur) {
			if(cur->next == NULL) {
				cur->next = newNode;
				break;
			}
			cur = cur->next;
		}
	}
}


template <class T>
T& Array<T>::operator[](int offSet)
{
	Node<T> *cur = pT;
    for (int i = 1; i<=offSet; i++)
		cur = cur->next;

	return *cur->data;
}

template <class T>
const T& Array<T>::operator[](int offSet) const
{
	Node<T> *cur = pT;
    for (int i = 1; i<=offSet; i++)
		cur = cur->next;

	return *cur->data;
}


